<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item
              :label="$t('key.cfDate')"
            >
              <a-date-picker v-model="postParams.qpsj"/>
            </a-form-item>
          </a-col>
          
          <template>
            <a-col :md="6" :sm="12">
              <a-form-item
                :label="$t('key.ddDate')"
              >
               <a-date-picker v-model="postParams.ddsj"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="12">
            <a-form-item
              :label="$t('key.cfd')"
            >
              <a-input v-model="queryParam.cfd"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="16">
            <span class="table-page-search-submitButtons">
                <!-- <a-button type="primary" @click="addReport" style="margin:0 10px">{{ $t('btn.add') }}</a-button> -->
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">{{ $t('button.query') }}</a-button>
              <a-button style="margin: 0 10px" @click="() => queryParam = {}">{{ $t('button.reset') }}</a-button>
              <a-button type="primary" style="margin: 0 10px" @click="exportThis">{{ $t('button.export') }}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    
    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        rowKey="index"
        :columns="columns"
        :data="loadData"
        :alert="{show: false}"
        :pagination="{ pageSize: 10 }"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>

        <template slot="operation" slot-scope="text, record">
            <a  @click="detailThis(record.id)">{{ $t('button.showStu') }}</a>
        </template>
      </s-table>
    </a-card>
    
    <check-modal
      ref="check"
      :visible="visible"
      :info ='rptInfo'
      @cancel="cancelThis"
      @refresh="$refs.table.refresh(true)"
    />
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import checkModal from './checkModal'
import moment from 'moment'
// import { delete } from 'vue/types/umd'

export default {
  name: 'report-review',
  data() {
    return {
      advanced: true,
      visible: false,
      rptInfo:{},
      postParams:{},
      queryParam: {},
      columns: [
        {
          title: this.$t('key.no'),
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: this.$t('key.name'),
          dataIndex: 'xsxx.xm'
        },
        {
          title: this.$t('key.ssyx'),
          dataIndex: 'xsxx.xjxx.ssyxmc'
        },
        {
          title: this.$t('key.zy'),
          dataIndex: 'xsxx.xjxx.sszymc'
        },
        {
          title: this.$t('key.stuCate'),
          dataIndex: 'xsxx.xjxx.pyccmc'
        },
        {
          title: this.$t('key.dsxm'),
          dataIndex: 'xsxx.xjxx.dsxm'
        },
        {
          title: this.$t('key.xmmc'),
          dataIndex: 'projectName'
        },
        {
          title: this.$t('key.cfDate'),
          dataIndex: 'cfDate'
        },
        {
          title: this.$t('key.cfd'),
          dataIndex: 'cfd'
        },
        
        {
          title: this.$t('key.ddDate'),
          dataIndex: 'ddDate'
        },
        {
          title: this.$t('key.option'),
          dataIndex: 'id',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        if(this.postParams.qpsj){
            params.cfdate = this.postParams.qpsj.format('YYYY-MM-DD');
        }else{
            delete params.cfdate
        }
        if(this.postParams.ddsj){
            params.dddate = this.postParams.ddsj.format('YYYY-MM-DD');
        }else {
            delete params.dddate
        }
        return this.$api.student.reportList(params).then(res => {
            res.data.rows.map(item =>{
                if(item.cfDate)item.cfDate=moment(item.cfDate).format('YYYY-MM-DD')
                if(item.ddDate)item.ddDate=moment(item.ddDate).format('YYYY-MM-DD')
            })
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {}
    }
  },
  components: { STable, checkModal },
//   computed: {
//     ...mapState({
//       TYPE0075: state => state.app['TYPE0075'], // 学生类别
//       TYPE0126: state => state.app['TYPE0126'], // 年级
//     })
//   },
//   created () {
//     this.$store.dispatch('app/setDictionary', 'TYPE0075')
//     this.$store.dispatch('app/setDictionary', 'TYPE0126')
//     this.initSelectMenu()
//   },
  methods: {
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zy', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zy', [])
      }
    },
    // editThis(id){
        
    //     this.$api.student.reportId(id).then(res =>{
    //         this.visible = true
    //          this.rptInfo = res.data
    //          this.$refs.check.title = '编辑机票信息'
    //     })
    // },
    // delThis(id){
    //     this.$api.student.reportDel(id).then(res =>{
    //         this.$message.success(res.msg)
    //         this.$refs.table.refresh(true)
    //     })
    // },
    // openCheck(id) {
    //   this.visible = true
    //   this.$api.student.projectId(id).then(res => {
    //     this.rptInfo = res.data
    //   })
    //   this.$nextTick(() => {
    //     this.$refs.check.form.resetFields()
    //   })
    // },
    // addReport(){
    //     this.visible = true
    //     this.$refs.check.title = '新增机票信息'
    // },
    cancelThis(){
        this.visible = false;
        this.$refs.check.form.resetFields()
    },
    detailThis(id){
      this.visible = true
      this.$api.student.reportDetile(id).then(res => {
        this.rptInfo = res.data
        this.$refs.check.type = 'detail'
      })
    },
    exportThis(){
         if(this.postParams.qpsj){
            this.queryParam.cfdate = this.postParams.qpsj.format('YYYY-MM-DD');
        }
        if(this.postParams.ddsj){
            this.queryParam.dddate = this.postParams.ddsj.format('YYYY-MM-DD');
        }
        this.$export('admissions/gjhxbd/export',this.queryParam)
    }
  }
}
</script>
